#ifndef LIST_H
#define LIST_H

template <class T>
struct ListItem
{
	T Value;
	ListItem* Next;
};

template <class T>
class List
{
private:
	int count;
	ListItem<T>* first;
public:
	List()
	{
		count = 0;
		first = 0;
	}

	void Add(T item)
	{
		if (first == 0)
		{
			first = new ListItem<T>();
			first->Value = item;
			first->Next = 0;

			count++;
		}
		else
		{
			ListItem<T>* tmp = first;
			
			while (tmp->Next != 0)
			{
				tmp = tmp->Next;
			}

			tmp->Next = new ListItem<T>();
			tmp->Next->Value = item;
			tmp->Next->Next = 0;

			count++;
		}
	}

	int GetCount()
	{
		return count;
	}

	T GetItemAt(int index)
	{
		int i = 0;
		ListItem<T>* tmp = first;

		while (i < index)
		{
			if (tmp == 0)
			{
				return 0;
			}

			tmp = tmp->Next;
			i++;
		}

		return tmp->Value;
	}
};

#endif